// pages/identityCard/identityCard.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datalist:[
      [1,'xx','xxx',1,0],
      [2,'xx','xxx',0,0],
      [3, 'xx', 'xxx', 0, 1]
    ],
    headImg: '',
    userInfo: wx.getStorageSync('trUserInfo'),
    year:'',
    month:'',
    day:'',
    sex:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var userId = this.data.userInfo.userId;
    wx.request({
      url: getApp().globalData.host_url + '/drugCard/ajax_viewUserDrugCard?userId=' + userId,
      method: 'GET',
      data: {},
      success: function (res) {
        var datalist = res.data.info;
        if (datalist == null) {
          var textToast = "信息获取失败！";
          wx.showToast({
            title: textToast,
            icon: '',
            duration: 2000
          })
        } else {
          that.setData({
            datalist: datalist,
            headImg: res.data.headImg
          });
        }
      },
      fail: function (res) {
        console.log('网络或服务异常')
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    var year = '';
    var month = '';
    var day = '';
    var idcard = that.data.userInfo.identityCard;
    if (idcard != null && idcard.length == 18) {
      var year = idcard.substring(6, 10);
      var month = idcard.substring(10, 12);
      var day = idcard.substring(12, 14);
    } else if (idcard != null && idcard.length == 15) {
      var year = "19" + idCard.substring(6, 8);
      var month = idcard.substring(8, 10);
      var day = idcard.substring(10, 12);
    }
    var sex = that.data.userInfo.sex;
    if(sex == '1')
    {
      sex = '男';
    } else if (sex == '2'){
      sex = '女';
    }else{
      sex = '未知';
    }
    // console.log(num)
    this.setData({
      year: year,
      month: month,
      day: day,
      sex: sex
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }

})